package org.dbstar.scheduler.actions;

import java.util.ArrayList;
import java.util.List;

import org.dbstar.scheduler.beans.JobDependency;
import org.dbstar.scheduler.beans.OperateType;
import org.dbstar.scheduler.control.JobConfController;
import org.dbstar.scheduler.control.JobDependencyController;
import org.quartz.Scheduler;
import org.quartz.Trigger;
import org.quartz.TriggerKey;
import org.quartz.impl.matchers.GroupMatcher;


/**
 * 显示Scheduler相关信息
 * 
 * @author 代波
 * @since 1.0.0
 * @version 1.0.0
 * @date 2012-4-18
 */
public class SchedulerAction extends ActionSupport {
	private Scheduler scheduler;
	private JobConfController jobConfController;
	private JobDependencyController jobDependencyController;

	private List<Trigger> triggers;
	private List<JobDependency> dependencies;

	public void setScheduler(Scheduler scheduler) {
		this.scheduler = scheduler;
	}

	public JobConfController getJobConfController() {
		return jobConfController;
	}

	public void setJobConfController(JobConfController jobConfController) {
		this.jobConfController = jobConfController;
	}

	public void setJobDependencyController(JobDependencyController jobDependencyController) {
		this.jobDependencyController = jobDependencyController;
	}

	public List<Trigger> getTriggers() {
		return triggers;
	}

	public List<JobDependency> getDependencies() {
		return dependencies;
	}

	@Override
	public String execute() throws Exception {
		triggers = new ArrayList<Trigger>();
		for (TriggerKey key : scheduler.getTriggerKeys(GroupMatcher.triggerGroupStartsWith("conf"))) {
			triggers.add(scheduler.getTrigger(key));
		}
		dependencies = jobDependencyController.getAllJobDependencies();
		operate(OperateType.triggers_list, String.valueOf(triggers.size()));
		return SUCCESS;
	}
}
